home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / botl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  10.0 KB  |  436 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)botl.c    3.1    93/01/17    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. #ifdef OVL0
  8. extern const char *hu_stat[];    /* defined in eat.c */
  9.  
  10. const char *enc_stat[] = {
  11.     "",
  12.     "Burdened",
  13.     "Stressed",
  14.     "Strained",
  15.     "Overtaxed",
  16.     "Overloaded"
  17. };
  18.  
  19. static void NDECL(bot1);
  20. static void NDECL(bot2);
  21. #endif /* OVL0 */
  22.  
  23. /* MAXCO must hold longest uncompressed status line, and must be larger
  24.  * than COLNO
  25.  *
  26.  * longest practical second status line at the moment is
  27.  *    Astral Plane $:12345 HP:700(700) Pw:111(111) AC:-127 Xp:30/123456789
  28.  *    T:123456 Satiated Conf Sick Blind Stun Hallu Overloaded
  29.  * -- or somewhat over 120 characters
  30.  */
  31. #if COLNO <= 130
  32. #define MAXCO 150
  33. #else
  34. #define MAXCO (COLNO+20)
  35. #endif
  36.  
  37. #ifndef OVLB
  38. STATIC_DCL int mrank_sz;
  39. #else /* OVLB */
  40. STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
  41. #endif /* OVLB */
  42.  
  43. struct rank_title {
  44.     char const * const    m;    /* male title */
  45.     char const * const    f;    /* female title, or 0 if same as male */
  46. };
  47. struct class_ranks {
  48.     char        plclass, fill_;
  49.     short        mplayer_class;
  50.     struct rank_title    titles[9];
  51. };
  52.  
  53. STATIC_DCL const struct rank_title *FDECL(rank_array, (CHAR_P));
  54. STATIC_DCL const char *NDECL(rank);
  55.  
  56. #ifdef OVL1
  57.  
  58. /* 9 pairs of ranks for each class */
  59.  
  60. static const
  61. struct class_ranks all_classes[] = {
  62.   {                    'A',0,    PM_ARCHEOLOGIST, {
  63.     {"Digger",    0},
  64.     {"Field Worker",0},
  65.     {"Investigator",0},
  66.     {"Exhumer",    0},
  67.     {"Excavator",    0},
  68.     {"Spelunker",    0},
  69.     {"Speleologist",0},
  70.     {"Collector",    0},
  71.     {"Curator",    0}
  72.   } },
  73.   {                    'B',0,    PM_BARBARIAN, {
  74.     {"Plunderer",    "Plunderess"},
  75.     {"Pillager",    0},
  76.     {"Bandit",    0},
  77.     {"Brigand",    0},
  78.     {"Raider",    0},
  79.     {"Reaver",    0},
  80.     {"Slayer",    0},
  81.     {"Chieftain",    "Chieftainess"},
  82.     {"Conqueror",    "Conqueress"}
  83.   } },
  84.   {                    'C',0,    PM_CAVEMAN, {
  85.     {"Troglodyte",    0},
  86.     {"Aborigine",    0},
  87.     {"Wanderer",    0},
  88.     {"Vagrant",    0},
  89.     {"Wayfarer",    0},
  90.     {"Roamer",    0},
  91.     {"Nomad",    0},
  92.     {"Rover",    0},
  93.     {"Pioneer",    0}
  94.   } },
  95.   {                    'E',0,    PM_ELF, {
  96.     {"Edhel",    "Elleth"},
  97.     {"Edhel",    "Elleth"},    /* elf-maid */
  98.     {"Ohtar",    "Ohtie"},    /* warrior */
  99.     {"Kano",            /* commander (Q.) ['a] */
  100.             "Kanie"}, /* educated guess, until further research- SAC */
  101.     {"Arandur",          /* king's servant, minister (Q.) - guess */
  102.             "Aranduriel"},    /* educated guess */
  103.     {"Hir",        "Hiril"},    /* lord, lady (S.) ['ir] */
  104.     {"Aredhel",    "Arwen"},    /* noble elf, maiden (S.) */
  105.     {"Ernil",    "Elentariel"},    /* prince (S.), elf-maiden (Q.) */
  106.     {"Elentar",    "Elentari"}    /* Star-king, -queen (Q.) */
  107.   } },
  108.   {                    'H',0,    PM_HEALER, {
  109.     {"Rhizotomist",  0},
  110.     {"Empiric",    0},
  111.     {"Embalmer",    0},
  112.     {"Dresser",    0},
  113.     {"Medici ossium",    0},
  114.     {"Herbalist",    0},
  115.     {"Magister",    0},
  116.     {"Physician",    0},
  117.     {"Chirurgeon",    0}
  118.   } },
  119.   {                    'K',0,    PM_KNIGHT, {
  120.     {"Gallant",    0},
  121.     {"Esquire",    0},
  122.     {"Bachelor",    0},
  123.     {"Sergeant",    0},
  124.     {"Knight",    0},
  125.     {"Banneret",    0},
  126.     {"Chevalier",    0},
  127.     {"Seignieur",    0},
  128.     {"Paladin",    0}
  129.   } },
  130.   {                    'P',0,    PM_PRIEST, {
  131.     {"Aspirant",    0},
  132.     {"Acolyte",    0},
  133.     {"Adept",    0},
  134.     {"Priest",    "Priestess"},
  135.     {"Curate",    0},
  136.     {"Canon",    "Canoness"},
  137.     {"Lama",    0},
  138.     {"Patriarch",    "Matriarch"},
  139.     {"High Priest", "High Priestess"}
  140.   } },
  141.   {                    'R',0,    PM_ROGUE, {
  142.     {"Footpad",    0},
  143.     {"Cutpurse",    0},
  144.     {"Rogue",    0},
  145.     {"Pilferer",    0},
  146.     {"Robber",    0},
  147.     {"Burglar",    0},
  148.     {"Filcher",    0},
  149.     {"Magsman",    "Magswoman"},
  150.     {"Thief",    0}
  151.   } },
  152.   {                    'S',0,    PM_SAMURAI, {
  153.     {"Hatamoto",    0},  /* Banner Knight */
  154.     {"Ronin",    0},  /* no allegiance */
  155.     {"Ninja",    0},  /* secret society */
  156.     {"Joshu",    0},  /* heads a castle */
  157.     {"Ryoshu",    0},  /* has a territory */
  158.     {"Kokushu",    0},  /* heads a province */
  159.     {"Daimyo",    0},  /* a samurai lord */
  160.     {"Kuge",    0},  /* Noble of the Court */
  161.     {"Shogun",    0}   /* supreme commander, warlord */
  162.   } },
  163. #ifdef TOURIST
  164.   {                    'T',0,    PM_TOURIST, {
  165.     {"Rambler",    0},
  166.     {"Sightseer",    0},
  167.     {"Excursionist",0},
  168.     {"Peregrinator","Peregrinatrix"},
  169.     {"Traveler",    0},
  170.     {"Journeyer",    0},
  171.     {"Voyager",    0},
  172.     {"Explorer",    0},
  173.     {"Adventurer",    0}
  174.   } },
  175. #endif
  176.   {                    'V',0,    PM_VALKYRIE, {
  177.     {"Stripling",    0},
  178.     {"Skirmisher",    0},
  179.     {"Fighter",    0},
  180.     {"Man-at-arms", "Woman-at-arms"},
  181.     {"Warrior",    0},
  182.     {"Swashbuckler",0},
  183.     {"Hero",    "Heroine"},
  184.     {"Champion",    0},
  185.     {"Lord",    "Lady"}
  186.   } },
  187.   {                    'W',0,    PM_WIZARD, {
  188.     {"Evoker",    0},
  189.     {"Conjurer",    0},
  190.     {"Thaumaturge", 0},
  191.     {"Magician",    0},
  192.     {"Enchanter",    "Enchantress"},
  193.     {"Sorcerer",    "Sorceress"},
  194.     {"Necromancer", 0},
  195.     {"Wizard",    0},
  196.     {"Mage",    0}
  197.   } },
  198. };
  199.  
  200. STATIC_OVL const struct rank_title *
  201. rank_array(pc)
  202. char pc;
  203. {
  204.     register int i;
  205.  
  206.     for (i = 0; i < SIZE(all_classes); i++)
  207.         if (all_classes[i].plclass == pc) return all_classes[i].titles;
  208.     return 0;
  209. }
  210.  
  211. /* convert experience level (1..30) to rank index (0..8) */
  212. int xlev_to_rank(xlev)
  213. int xlev;
  214. {
  215.     return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8;
  216. }
  217.  
  218. #if 0    /* not currently needed */
  219. /* convert rank index (0..8) to experience level (1..30) */
  220. int rank_to_xlev(rank)
  221. int rank;
  222. {
  223.     return (rank <= 0) ? 1 : (rank <= 8) ? ((rank * 4) - 2) : 30;
  224. }
  225. #endif
  226.  
  227. const char *
  228. rank_of(lev, pc, female)
  229. register unsigned lev;
  230. char pc;
  231. boolean female;
  232. {
  233.     register int idx = xlev_to_rank((int)lev);
  234.     const struct rank_title *ranks = rank_array(pc);
  235.  
  236.     if (ranks)
  237.         return( female && ranks[idx].f ? ranks[idx].f : ranks[idx].m );
  238.     return(pl_character);
  239. }
  240.  
  241. STATIC_OVL const char *
  242. rank()
  243. {
  244.     return(rank_of(u.ulevel, pl_character[0], flags.female));
  245. }
  246.  
  247. int
  248. title_to_mon(str, rank_indx, title_length)
  249. const char *str;
  250. int *rank_indx, *title_length;
  251. {
  252.     register int i, j;
  253.     register const struct rank_title *ttl;
  254.  
  255.     for (i = 0; i < SIZE(all_classes); i++)
  256.         for (j = 0; j < 9; j++) {
  257.         ttl = &all_classes[i].titles[j];
  258.         if (!strncmpi(ttl->m, str, strlen(ttl->m))) {
  259.             if (rank_indx) *rank_indx = j;
  260.             if (title_length) *title_length = strlen(ttl->m);
  261.             return all_classes[i].mplayer_class;
  262.         } else if (ttl->f && !strncmpi(ttl->f, str, strlen(ttl->f))) {
  263.             if (rank_indx) *rank_indx = j;
  264.             if (title_length) *title_length = strlen(ttl->f);
  265.             return all_classes[i].plclass == 'C' ? PM_CAVEWOMAN :
  266.                all_classes[i].plclass == 'P' ? PM_PRIESTESS :
  267.                all_classes[i].mplayer_class;
  268.         }
  269.         }
  270.     return -1;    /* not found */
  271. }
  272.  
  273. #endif /* OVL1 */
  274. #ifdef OVLB
  275.  
  276. void
  277. max_rank_sz()
  278. {
  279.     register int i, r, maxr = 0;
  280.     const struct rank_title *ranks = rank_array(pl_character[0]);
  281.  
  282.     if (ranks) {
  283.         for (i = 0; i < 9; i++) {
  284.         if ((r = strlen(ranks[i].m)) > maxr) maxr = r;
  285.         if (ranks[i].f)
  286.             if ((r = strlen(ranks[i].f)) > maxr) maxr = r;
  287.         }
  288.         mrank_sz = maxr;
  289.     }
  290.     else mrank_sz = strlen(pl_character);
  291. }
  292.  
  293. #endif /* OVLB */
  294. #ifdef OVL0
  295.  
  296. #ifdef SCORE_ON_BOTL
  297. long
  298. botl_score()
  299. {
  300.     int deepest = deepest_lev_reached(FALSE);
  301.     long ugold = u.ugold + hidden_gold();
  302.  
  303.     if ((ugold -= u.ugold0) < 0L) ugold = 0L;
  304.     return ugold + u.urexp + (long)(50 * (deepest - 1))
  305.               + (long)(deepest > 30 ? 10000 :
  306.                    deepest > 20 ? 1000*(deepest - 20) : 0);
  307. }
  308. #endif
  309.  
  310. static void
  311. bot1()
  312. {
  313.     char newbot1[MAXCO];
  314.     register char *nb;
  315.     register int i,j;
  316.  
  317.     Strcpy(newbot1, plname);
  318.     if('a' <= newbot1[0] && newbot1[0] <= 'z') newbot1[0] += 'A'-'a';
  319.     newbot1[10] = 0;
  320.     Sprintf(nb = eos(newbot1)," the ");
  321. #ifdef POLYSELF
  322.     if (u.mtimedone) {
  323.         char mbot[BUFSZ];
  324.         int k = 0;
  325.  
  326.         Strcpy(mbot, mons[u.umonnum].mname);
  327.         while(mbot[k] != 0) {
  328.             if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) &&
  329.                     'a' <= mbot[k] && mbot[k] <= 'z')
  330.             mbot[k] += 'A' - 'a';
  331.             k++;
  332.         }
  333.         Sprintf(nb = eos(nb), mbot);
  334.     } else
  335.         Sprintf(nb = eos(nb), rank());
  336. #else
  337.     Sprintf(nb = eos(nb), rank());
  338. #endif
  339.     Sprintf(nb = eos(nb),"  ");
  340.     i = mrank_sz + 15;
  341.     j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */
  342.     if((i - j) > 0)
  343.         Sprintf(nb = eos(nb),"%*s", i-j, " ");    /* pad with spaces */
  344.     if (ACURR(A_STR) > 18) {
  345.         if (ACURR(A_STR) > 118)
  346.             Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100);
  347.         else if (ACURR(A_STR) < 118)
  348.             Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18);
  349.         else
  350.             Sprintf(nb = eos(nb),"St:18/** ");
  351.     } else
  352.         Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR));
  353.     Sprintf(nb = eos(nb),
  354.         "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
  355.         ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA));
  356.     Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? "  Chaotic" :
  357.             (u.ualign.type == A_NEUTRAL) ? "  Neutral" : "  Lawful");
  358. #ifdef SCORE_ON_BOTL
  359.     if (flags.showscore)
  360.         Sprintf(nb = eos(nb), " S:%ld", botl_score());
  361. #endif
  362.     curs(WIN_STATUS, 1, 0);
  363.     putstr(WIN_STATUS, 0, newbot1);
  364. }
  365.  
  366. static void
  367. bot2()
  368. {
  369.     char  newbot2[MAXCO];
  370.     register char *nb;
  371.     int hp, hpmax;
  372.     int cap = near_capacity();
  373.  
  374. #ifdef POLYSELF
  375.     hp = u.mtimedone ? u.mh : u.uhp;
  376.     hpmax = u.mtimedone ? u.mhmax : u.uhpmax;
  377. #else
  378.     hp = u.uhp;
  379.     hpmax = u.uhpmax;
  380. #endif
  381.     if(hp < 0) hp = 0;
  382. /* TODO:    Add in dungeon name */
  383. #ifdef MULDGN
  384.     if(Is_knox(&u.uz)) Sprintf(newbot2, "%s ", dungeons[u.uz.dnum].dname);
  385.     else
  386.     if(In_quest(&u.uz)) Sprintf(newbot2, "Home %d ", dunlev(&u.uz));
  387.     else
  388. #endif
  389.     if(In_endgame(&u.uz))
  390.         Sprintf(newbot2,
  391.             Is_astralevel(&u.uz) ? "Astral Plane " : "End Game ");
  392.     else
  393.         Sprintf(newbot2, "Dlvl:%-2d ", depth(&u.uz));
  394.     Sprintf(nb = eos(newbot2),
  395.         "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", oc_syms[GOLD_CLASS],
  396.         u.ugold, hp, hpmax, u.uen, u.uenmax, u.uac);
  397. #ifdef POLYSELF
  398.     if (u.mtimedone)
  399.         Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
  400.     else
  401. #endif
  402. #ifdef EXP_ON_BOTL
  403.     if(flags.showexp)
  404.         Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp);
  405.     else
  406. #endif
  407.     Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
  408.     if(flags.time)
  409.         Sprintf(nb = eos(nb), " T:%ld", moves);
  410.     if(strcmp(hu_stat[u.uhs], "        ")) {
  411.         Sprintf(nb = eos(nb), " ");
  412.         Strcat(newbot2, hu_stat[u.uhs]);
  413.     }
  414.     if(Confusion)       Sprintf(nb = eos(nb), " Conf");
  415.     if(Sick)       Sprintf(nb = eos(nb), " Sick");
  416.     if(Blind)       Sprintf(nb = eos(nb), " Blind");
  417.     if(Stunned)       Sprintf(nb = eos(nb), " Stun");
  418.     if(Hallucination)  Sprintf(nb = eos(nb), " Hallu");
  419.     if(cap > UNENCUMBERED)
  420.         Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
  421.     curs(WIN_STATUS, 1, 1);
  422.     putstr(WIN_STATUS, 0, newbot2);
  423. }
  424.  
  425. void
  426. bot()
  427. {
  428.     bot1();
  429.     bot2();
  430.     flags.botl = flags.botlx = 0;
  431. }
  432.  
  433. #endif /* OVL0 */
  434.  
  435. /*botl.c*/
  436.